package metalink.admin;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;
import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;

import java.io.*;

import javax.servlet.http.HttpSession;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
public class ReadFromExcel extends ActionSupport {
	File excel_file;
	ArrayList<CollegeStaffVo> staff_list=new ArrayList<CollegeStaffVo>();
	
	
	public ArrayList<CollegeStaffVo> getStaff_list() {
		return staff_list;
	}

	public void setStaff_list(ArrayList<CollegeStaffVo> staff_list) {
		this.staff_list = staff_list;
	}

	public File getExcel_file() {
		return excel_file;
	}

	public void setExcel_file(File excel_file) {
		this.excel_file = excel_file;
	}

	public String execute(){
		try{
			File f=new File("temp.csv");
			FileUtils.copyFile(excel_file, f);
			FileReader fr=new FileReader(f);
			BufferedReader br=new BufferedReader(fr);
			String str="";
			while(null!=(str=br.readLine())){
				String[] values=str.split(",");
				CollegeStaffVo single_object=new CollegeStaffVo();
				single_object.setStaff_name(values[0]);
				single_object.setRoll_number(values[1]);
				single_object.setDesignation(values[2]);
				single_object.setJoining_date(values[3]);
				single_object.setPhone_number(values[4]);
				single_object.setAcc_no(Integer.parseInt(values[12]));
				single_object.setStaff_type(Integer.parseInt(values[10]));
				staff_list.add(single_object);
				
				
			}
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.setAttribute("uploaded_staff_list",staff_list);
			return SUCCESS;
		}
		catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
	}

}
